var testapi = "http://test.api.malatoday.com/";
var url = "public/login";
Vue.component('default-nav', {
  template: `        <div><div class="navbar-fixed nav-extended">
            <nav class="white darken-4 ">
                <div class="nav-wrapper container">
                    <a href="#!" class="brand-logo grey-text">LOGO</a>
                    <a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons grey-text">menu</i></a>
                    <ul class="right hide-on-med-and-down">
                        <li class="active"><a class="grey-text waves-effect" href="#!"><i class="material-icons left grey-text">home</i>首页</a></li>
                        <li><a class="grey-text waves-effect" href="#!"><i class="material-icons left grey-text">search</i>搜索</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="#!">登录</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="#!">注册</a></li>
                        <li>
                            <a style="max-height:64px;padding-top:5px;" href="#"><img class="circle" style="border: medium solid white;max-height:54px;" src="https://kejun.space/assets/images/photo.jpg"></a>
                        </li>
                    </ul>
                </div>
            </nav>
        </div>
        <ul id="slide-out" class="side-nav">
            <li>
                <div class="userView">
                    <div class="background">
                    </div>
                    <a href="#!user"><img class="circle" style="border: medium solid white" src="https://kejun.space/assets/images/photo.jpg"></a>
                    <a href="#!name"><span class="white-text name">KeJun</span></a>
                    <a href="#!email"><span class="white-text email">kejun1997@gmail.com</span></a>
                </div>
            </li>
            <li><a class="subheader">Page</a></li>
            <li class="active"><a class=" waves-effect" href="#!"><i class="material-icons">home</i>首页</a></li>
            <li><a class="waves-effect" href="#!"><i class="material-icons">search</i>搜索</a></li>
            <li>
                <div class="divider"></div>
            </li>
            <li><a class="subheader">Sign in or Sign up</a></li>
            <li><a class="waves-effect" href="#!">登录</a></li>
            <li><a class="waves-effect" href="#!">注册</a></li>
        </ul></div>`
});

Vue.component('index-nav', {
  template: `        <div><div class="navbar-fixed nav-extended">
            <nav class="white darken-4 ">
                <div class="nav-wrapper container">
                    <a href="#!" class="brand-logo grey-text">LOGO</a>
                    <a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons grey-text">menu</i></a>
                    <ul class="right hide-on-med-and-down">
                        <li class="active"><a class="grey-text waves-effect" href="#!"><i class="material-icons left grey-text">home</i>首页</a></li>
                        <li><a class="grey-text waves-effect" href="#!"><i class="material-icons left grey-text">search</i>搜索</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="login">登录</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="register">注册</a></li>
                    </ul>
                </div>
            </nav>
        </div>
        <ul id="slide-out" class="side-nav">
            <li>
                <div class="userView" style="min-height: 160px;">
                    <div class="background">
                    </div>
                    <p class="white-text">请先登录</p>
                </div>
            </li>
            <li><a class="subheader">Page</a></li>
            <li class="active"><a class=" waves-effect" href="#!"><i class="material-icons">home</i>首页</a></li>
            <li><a class="waves-effect" href="#!"><i class="material-icons">search</i>搜索</a></li>
            <li>
                <div class="divider"></div>
            </li>
            <li><a class="subheader">Sign in or Sign up</a></li>
            <li><a class="waves-effect" href="#!">登录</a></li>
            <li><a class="waves-effect" href="#!">注册</a></li>
        </ul></div>`
});
Vue.component('login-nav', {
  template: `        <div><div class="navbar-fixed nav-extended">
            <nav class="white darken-4 ">
                <div class="nav-wrapper container">
                    <a href="#!" class="brand-logo grey-text">LOGO</a>
                    <a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons grey-text">menu</i></a>
                    <ul class="right hide-on-med-and-down">
                        <li><a class="grey-text waves-effect" href="../"><i class="material-icons left grey-text">home</i>首页</a></li>
                        <li><a class="grey-text waves-effect" href="../search"><i class="material-icons left grey-text">search</i>搜索</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="../register">注册</a></li>
                    </ul>
                </div>
            </nav>
        </div>
        <ul id="slide-out" class="side-nav">
            <li>
                <div class="userView" style="min-height: 160px;">
                    <div class="background">
                    </div>
                    <p class="white-text">请先登录</p>
                </div>
            </li>
            <li><a class="subheader">Page</a></li>
            <li><a class=" waves-effect" href="#!"><i class="material-icons">home</i>首页</a></li>
            <li><a class="waves-effect" href="#!"><i class="material-icons">search</i>搜索</a></li>
            <li>
                <div class="divider"></div>
            </li>
            <li><a class="subheader">Sign in or Sign up</a></li>
            <li class="active"><a class="waves-effect" href="#!">登录</a></li>
            <li><a class="waves-effect" href="#!">注册</a></li>
        </ul></div>`
});
Vue.component('register-nav', {
  template: `        <div><div class="navbar-fixed nav-extended">
            <nav class="white darken-4 ">
                <div class="nav-wrapper container">
                    <a href="../" class="brand-logo grey-text">LOGO</a>
                    <a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons grey-text">menu</i></a>
                    <ul class="right hide-on-med-and-down">
                        <li><a class="grey-text waves-effect" href="../"><i class="material-icons left grey-text">home</i>首页</a></li>
                        <li><a class="grey-text waves-effect" href="../search"><i class="material-icons left grey-text">search</i>搜索</a></li>
                        <li><a class="btn waves-effect grey waves-light" href="../login">登录</a></li>
                    </ul>
                </div>
            </nav>
        </div>
        <ul id="slide-out" class="side-nav">
            <li>
                <div class="userView" style="min-height: 160px;">
                    <div class="background">
                    </div>
                    <p class="white-text">请先登录</p>
                </div>
            </li>
            <li><a class="subheader">Page</a></li>
            <li><a class=" waves-effect" href="#!"><i class="material-icons">home</i>首页</a></li>
            <li><a class="waves-effect" href="#!"><i class="material-icons">search</i>搜索</a></li>
            <li>
                <div class="divider"></div>
            </li>
            <li><a class="subheader">Sign in or Sign up</a></li>
            <li class="active"><a class="waves-effect" href="#!">登录</a></li>
            <li><a class="waves-effect" href="#!">注册</a></li>
        </ul></div>`
});

var data = {
  type: 'index'
};
var stoken, ltoken;
var href = window.location.href;
var loginpage = href.indexOf('login');
var registerpage = href.indexOf('register');
ltoken = $.cookie('token');
if (ltoken) {
  $.post(testapi + url, {
    username: "username",
    password: "password"
  }, function (token) {
    stoken = token.token;
  });
  if (ltoken == stoken) {
    data.type = "user";
  }
}else if(loginpage > 0){
    data.type = "login";
}else if (registerpage > 0){
    data.type = "register";
}
var nav = new Vue({
  el: '#nav',
  data: data
});